﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;

namespace Xpom_Xpum__Code_Generator.Subsystems
{
    internal class ProjectManager
    {
        internal Core.ProjectClass ProjectObject;

        internal void Create(string path, string templateName)
        {
            string templatePath = GlobalVariables.GetSDKPath() + @"Templates\" +
                   templateName + @"\";

            ProjectObject = new Core.ProjectClass(path, templatePath);
        }

        internal object GetProperty(string property)
        {
            return ProjectObject.ManifestObject.GetType().GetProperty(property).GetValue(ProjectObject.ManifestObject, null);
            /*switch (property)
            {
                case "name":
                    return ProjectObject.ProjectName;
                default:
                    return "";
            }*/
        }

        internal void Save()
        {
            ProjectObject.Save();
        }

        internal void AddProperty(string property)
        {
            ProjectObject.ManifestObject.JObjectCore.Add(property, "");
        }

        internal void RemoveProperty(string property)
        {
            ProjectObject.ManifestObject.JObjectCore.Remove(property);
        }

        internal void SetProperty(string property, string value)
        {
            var prop = ProjectObject.ManifestObject.GetType().GetProperty(property);
            if (prop.PropertyType == typeof(Int32))
            {
                prop.SetValue(ProjectObject.ManifestObject, Convert.ToInt32(value), null);
            }
            else
            {
                prop.SetValue(ProjectObject.ManifestObject, value, null);
            }
            /*
            switch (property)
            {
                case "name":
                    ProjectObject.ProjectName = value;
                    break;
                default:
                    break;
            }*/
        }
    }
}
